package com.gzyj.jtt808.v2019.protocol;

import com.gzyj.jtt808.utils.HexBytesUtil;
import com.gzyj.jtt808.v2019.Package;
import com.gzyj.jtt808.v2019.enums.BusinessDataType;
import io.netty.buffer.ByteBuf;
import lombok.Data;

import java.io.Serializable;
import java.nio.charset.Charset;

@Data
public class JTT808_0x8300 extends Package implements Serializable {
    private Byte TextFlag;//文本信息标志位含义见 表 38
    private Byte TextType;//文本类型
    private String TextInfo;//文本信息 最长为 1024 字节，经GBK编码

    public JTT808_0x8300() {
        super(BusinessDataType.文本信息下发.getCode());
    }


    @Override
    public void encodeImpl(ByteBuf buf) {

        buf.writeByte(this.TextFlag);
        buf.writeByte(this.TextType);
        buf.writeCharSequence(TextInfo, Charset.forName("GBK"));

    }

    @Override
    public JTT808_0x8300 decodeImpl(ByteBuf buf) {
        this.TextFlag = buf.readByte();
        this.TextType = buf.readByte();
        byte[] t = HexBytesUtil.readByOffset(buf, buf.readableBytes());
        this.TextInfo = new String(t, Charset.forName("GBK"));
        return this;
    }
}
